using net_work.Config;
using net_work.Data.DTO.Cam;
using net_work.Data.Entity.Cam;
using net_work.IRepository.Cam;

namespace net_work.Repository.Cam;

public class ApplyRepository(ApplicationDbContext dbContext)
    : Repository<Apply>(dbContext), IApplyRepository
{
    public async Task<long> InsertAsync(ApplyAddRequestBackend applyAddRequestBackend)
    {
        var newApply = new Apply
        {
            Content = applyAddRequestBackend.Content,
            UserId = applyAddRequestBackend.UserId,
            Remark = applyAddRequestBackend.Remark
        };
        await dbContext.Applies.AddAsync(newApply);
        await dbContext.SaveChangesAsync();
        return newApply.Id;
    }

    public async Task<bool> UpdateAsync(ApplyUpdateRequest applyUpdateRequest)
    {
        var apply = await dbContext.Applies.FindAsync(applyUpdateRequest.Id);
        if (apply == null)
        {
            return false;
        }

        apply.Remark = applyUpdateRequest.Remark;
        apply.Content = applyUpdateRequest.Content;
        await dbContext.SaveChangesAsync();

         await dbContext.SaveChangesAsync();
        return true;
    }
}